package com.base.system.managedBean;

import java.io.Serializable;

import javax.faces.context.FacesContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.BeforeRender;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.user.util.Browser;

import com.base.system.managedBean.baseBean.BasePositionBean;

@ManagedBean(name = "system_editPositonBean", scope = ManagedBeanScope.REQUEST)
public class EditPositonBean extends BasePositionBean implements Serializable {

	private final static Log logger = LogFactory.getLog(EditPositonBean.class);
	@Inject
	private FacesContext context;

	@SaveState
	private String unid;

	@BeforeRender
	public void beforeRender(boolean isPostback) {
		if (!isPostback) {
			unid = context.getExternalContext().getRequestParameterMap().get(
					"id");
			if (!"".equals(unid) && null != unid) {
				post = postDao.getById(Integer.valueOf(unid));
			}
			this.getPositonProperty();
		}
	}

	@Action(id = "save")
	public void save() {
		post = postDao.getById(Integer.valueOf(unid));
		this.setPostProperty();
		postDao.saveOrUpdate(post);
		String script = "closeCenterLayoutTab('editPositionTab')";
		Browser.execClientScript("window.top", script);
	}
}
